<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />


    <link href="/static/v5/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/static/v5/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/v5/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link href="/static/v5/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="/static/v5/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/static/v5/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
    <title>更新角色</title>
</head>
<body>
<nav class="breadcrumb">
    <button type="submit" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px; margin-left: 5px" onclick="javascript:history.back(-1);" >返回</button>
</nav>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>帐号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text"  th:value="${admin.user_name}" placeholder="" id="user_name" name="user_name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" placeholder="" id="user_pass" name="user_pass">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>电话：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text"  th:value="${admin.phone}" placeholder="" id="phone" name="phone">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
			     <select name="articlecolumn" class="select" id="role_id">
                    <th:block  th:each="role: ${roles}">
                           <th:block  th:if="${admin.role_id == role.role_id}" >
                                    <option th:value="${role.role_id}" th:text="${role.role_name}" th:selected="selected"></option>
                           </th:block>
                           <th:block  th:if="${admin.role_id != role.role_id}" >
                                    <option th:value="${role.role_id}" th:text="${role.role_name}"></option>
                           </th:block>
                    </th:block>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" id="submit_bt" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<script type="text/javascript" src="/static/v5/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $("#submit_bt").click(function () {
        if(!(/^.{1,16}$/.test($("#user_name").val()))){
            alert("名称最多16个字符");
            return;
        }
        if(!(/^.{6,16}$/.test($("#user_pass").val()))){
            alert("密码6-16个字符");
            return;
        }
        if(!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test($("#phone").val()))){
            alert("请输入正确的手机号码");
            return;
        }
        /*<![CDATA[*/
        var admin_id = [[${admin.admin_id}]];
        /*]]>*/
        var dataJson = {
            user_name:$("#user_name").val(),
            user_pass:$("#user_pass").val(),
            phone:$("#phone").val(),
            role_id:$("#role_id").val(),
            admin_id:admin_id,
        }

        $.ajax({
            type: 'post',
            url: '/v5/admin/accounts/update'+ "?token="  + sessionStorage.getItem("token") ,
            dataType: 'json',
            data: JSON.stringify(dataJson),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data.mark == "0") {
                    window.location.href="/v5/admin/accounts/list?father_id=4&current_page=1" + "&token="  + sessionStorage.getItem("token")
                } else {
                    alert(data.tip);
                }
            }

        });
    });
</script>
</body>
</html>





